﻿using Koala.Pro.Models;
using Newtonsoft.Json;

namespace Koala.Pro.Helpers
{
    [Serializable]
    public class TreeNodeItem
    {
        public string Id { get; set; }

        public string Value { get; set; }

        public string Label { get; set; }

        public string Key { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore)]
        public List<TreeNodeItem> children { get; set; }

        public TreeNodeItem()
        {
        }

        public TreeNodeItem(CListItem item)
            : this(item.Value, item.Text)
        {
        }

        public TreeNodeItem(string id, string label, string key = null)
            : this()
        {
            Id = id;
            Value = id;
            Label = label;
            Key = key;
        }

        public TreeNodeItem(int id, string label, string key = null)
            : this(id.ToString(), label)
        {
            Key = key;
        }

        public TreeNodeItem(string text)
            : this(text, text)
        {
        }

        public override string ToString()
        {
            return Label.ToString();
        }
    }
}
